package com.system.xingzhi.controller;

import com.system.xingzhi.model.ReturnData;
import com.system.xingzhi.model.Component;
import com.system.xingzhi.service.ComponentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController("/component")
@CrossOrigin
@Api(value = "/component",tags = {"组件"},description = "组件管理")
public class ComponentController {

    @Autowired
    private ComponentService componentService;

    @PostMapping(value="/addComponent")
    @ApiOperation(notes = "增加组件",value = "增加组件")
    public ReturnData addUser(@ModelAttribute Component component){
        return  componentService.insert(component);
    }

    @PostMapping(value="/deleteComponent")
    @ApiOperation(notes = "删除组件",value = "删除组件")
    public ReturnData deleteUser(@ApiParam(name = "componentId",value = "组件id") @RequestParam("componentId") String componentId){
        return  componentService.deleteByPrimaryKey(componentId);
    }

    @PostMapping(value="/updateComponent")
    @ApiOperation(notes = "更新组件",value = "更新组件")
    public ReturnData updateUser(@ModelAttribute Component component){
        return  componentService.updateByPrimaryKey(component);
    }

    @GetMapping(value="/queryComponent")
    @ApiOperation(notes = "组件查询",value = "组件查询")
    public ReturnData queryUser(
            @ApiParam(name = "keyWord",value = "组件名") @RequestParam(value = "keyWord",required = false) String keyWord,
            @ApiParam(name = "pageNum",value = "页码") @RequestParam(value="pageNum") Integer pageNum,
            @ApiParam(name = "pageSize",value = "分页条数") @RequestParam(value="pageSize") Integer pageSize
    ){
        Map<String,String> map=new HashMap<>();
        map.put("keyWord",keyWord);
        return  componentService.selectByParameter(map,pageNum,pageSize);
    }
    @GetMapping(value="/getAllComponent")
    @ApiOperation(notes = "获取所有组件",value = "获取所有组件")
    public ReturnData getAllComponent() {
        return componentService.getAllComponent();
    }
}
